package com.example.androiddev.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.example.androiddev.R;
import com.example.androiddev.base.BaseActivity;
import com.example.androiddev.bean.Weather;
import com.example.commonlib.utils.GsonUtil;
import com.example.commonlib.utils.LogUtils;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import rxhttp.wrapper.param.RxHttp;

/**
 * Created by zxw.
 * CreateDate: 2019/12/20 17:33
 * Description: 页面描述
 */
public class ArrayUtilsActivity extends BaseActivity {

    private TextView textView;

    private static final String TAG = "ArrayUtilsActivity";


    /**
     * 上下文
     */
    private Context context = ArrayUtilsActivity.this;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_array_utils_layout;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle(TAG);
        textView = findViewById(R.id.text);
    }

    @Override
    protected void initData() {
        super.initData();
        doHttp();
    }

    private void doHttp() {
        RxHttp.get("/mobile/get")
                .add("key", "4fcd8927e0ab52111d888173ff50c083")
                .add("phone", "17602176996").asString()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        LogUtils.d("zxw", s);
                        Weather weather = GsonUtil.Json2Result(Weather.class, s);
                        if (weather.getResultcode().equals("200")) {
                            textView.setText(weather.getResult().getCity() + ":" + weather.getResult().getCompany());
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        LogUtils.e("zxw", e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
